Add regex and IPv4 CIDR range functions#13
Merged
Conversation
Add four dependency-free built-ins to @pro-fa/expreszo: - regexMatches(str, pattern, flags?) — boolean match test - regexExtract(str, pattern, flags?) — first match or capture groups - regexReplace(str, pattern, replacement, flags?) — regex replace (defaults to global) - ipInRange(ip, cidr) — IPv4 CIDR membership via native 32-bit math Wired into the registry, runtime parser functions map, and builtin docs; the language service and MCP server pick them up automatically. Updates the docs (syntax + quick reference) and adds a language-service sample entry. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR adds four new dependency-free built-in functions to @pro-fa/expreszo—three regex helpers and an IPv4 CIDR membership check—then wires them into the built-in function registry, legacy Parser.functions map, docs, samples, and tests, along with a package version bump.
Changes:
- Add
regexMatches,regexExtract,regexReplace(string) andipInRange(utility) implementations and export them through the functions barrels. - Register the new built-ins in the descriptor registry and legacy parser function map; add language-service sample usage.
- Add documentation and introduce new TypeScript tests for regex and network functionality; bump package version to
0.6.6.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| samples/language-service-sample/examples.js | Adds a sample showcasing the new regex and CIDR functions in the language-service demo. |
| packages/expreszo/test/functions/functions-regex.ts | Adds test coverage for the new regex built-in functions. |
| packages/expreszo/test/functions/functions-network.ts | Adds test coverage for the new ipInRange built-in function. |
| packages/expreszo/src/registry/builtin/functions.ts | Registers the new built-ins in the function descriptor catalog. |
| packages/expreszo/src/registry/builtin/function-docs.ts | Adds language-service docs metadata for the new functions. |
| packages/expreszo/src/parsing/parser.ts | Adds the new functions to the legacy Parser.functions registry for parity. |
| packages/expreszo/src/functions/utility/network.ts | Implements ipInRange and IPv4 parsing logic. |
| packages/expreszo/src/functions/utility/index.ts | Re-exports the new utility/network functions. |
| packages/expreszo/src/functions/string/regex.ts | Implements regex match/extract/replace built-ins. |
| packages/expreszo/src/functions/string/index.ts | Re-exports the new string/regex functions. |
| packages/expreszo/package.json | Bumps @pro-fa/expreszo version to 0.6.6. |
| docs/syntax.md | Documents regex functions and ipInRange, plus adds examples and caveats. |
| docs/quick-reference.md | Adds quick-reference entries for regex functions and a network section for ipInRange. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+70
to
+73
| const match = str.match(compile('regexExtract', pattern, flags)); | ||
| if (match === null) { | ||
| return undefined; | ||
| } |
| | if(c, a, b) | Function form of c ? a : b. Uses lazy evaluation: only the matching branch is evaluated. | | ||
| | coalesce(a, b, ...) | Returns the first non-null and non-empty string value from the arguments. Numbers and booleans (including 0 and false) are considered valid values. | | ||
| | json(value) | Converts a value to a JSON string representation. | | ||
| | ipInRange(ip, cidr) | Returns `true` if the IPv4 address `ip` falls within the CIDR block `cidr` (e.g. `"10.0.0.0/8"`), `false` otherwise. IPv4 only. | |
Comment on lines
+19
to
+20
| // Reject empty, signs, whitespace, and non-numeric octets; require a plain | ||
| // decimal integer 0–255 with no leading-zero ambiguity beyond "0". |
Comment on lines
+52
to
+70
| describe('regexExtract(str, pattern, flags?)', function () { | ||
| it('should return the full match when there are no capture groups', function () { | ||
| const parser = new Parser(); | ||
| assert.strictEqual(parser.evaluate('regexExtract("abc123def", "[0-9]+")'), '123'); | ||
| }); | ||
|
|
||
| it('should return capture groups as an array when present', function () { | ||
| const parser = new Parser(); | ||
| assert.deepStrictEqual(parser.evaluate('regexExtract("user-42", "user-([0-9]+)")'), ['42']); | ||
| assert.deepStrictEqual( | ||
| parser.evaluate('regexExtract("2026-06-22", "([0-9]+)-([0-9]+)-([0-9]+)")'), | ||
| ['2026', '06', '22'] | ||
| ); | ||
| }); | ||
|
|
||
| it('should return undefined when there is no match', function () { | ||
| const parser = new Parser(); | ||
| assert.strictEqual(parser.evaluate('regexExtract("abc", "[0-9]+")'), undefined); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds four dependency-free built-in functions to
@pro-fa/expreszoand bumps the package to 0.6.6.regexMatches(str, pattern, flags?)true/falseif the string matches the regexregexExtract(str, pattern, flags?)undefinedif no matchregexReplace(str, pattern, replacement, flags?)ipInRange(ip, cidr)trueif the IPv4 address is inside the CIDR block; native 32-bit math, IPv4 onlyAll four are
pure: true,safe: true, sync, and add no new dependencies.Implementation notes
functions/string/regex.ts,functions/utility/network.ts.registry/builtin/functions.ts+function-docs.ts) and the legacy runtimeParser.functionsmap (parsing/parser.ts) — a parity test enforces the two stay in lock-step.Caveats
"\d"in expression source; character classes like"[0-9]"need no escaping. Documented indocs/syntax.mdand the sample.Docs & samples
docs/syntax.md: new Regular Expressions subsection +ipInRangein the Utility table + examples.docs/quick-reference.md: regex rows and a Network Functions section.samples/language-service-sample/examples.js: a "Regex & IP Range Functions" example.Testing
test/functions/functions-regex.ts,test/functions/functions-network.ts.regex.ts100% lines.mcp-servertests: 12/12 pass.🤖 Generated with Claude Code